package com.cy.comstore;

import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication
//注解指定当前项目中的mapper接口路径，项目启时会自动加载所有的接口文件
@MapperScan("com.cy.comstore.mapper")
@Configuration //为文件大小设置配置类
public class ComSToreApplication {

    public static void main(String[] args) {
        SpringApplication.run(ComSToreApplication.class, args);
    }

    @Bean
    public MultipartConfigElement getElement(){
        //使用工厂模式创建一个配置的工厂类对象
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //设置需要创建对象的相关信息
        factory.setMaxFileSize(DataSize.of(10, DataUnit.MEGABYTES));
        factory.setMaxRequestSize(DataSize.of(15,DataUnit.MEGABYTES));
        //返回工厂创建的config元素
        return factory.createMultipartConfig();
    }
}
